<?php
include 'header2.php';
error_reporting(E_ALL);
ini_set('display_errors','1');
?>

			<!-----------------------------------------------------la colonne droite---------------------------------------------------------------->

			<div id="colonne_droite">
				<h2>Bienvenu sur La page de l'inscription </h2></br></br></br>
				<P>
					<strong><font size = 4 COLOR="navy"> Vous êtes dans la page d'inscription qui concerne </br>les Anciens élèves ingenieurs de Polytech'montpellier.</br></br>
						Cette page ne concerne que les dîplomés de Polytech'Montpellier</br></br>
						Si Vous êtes actuellement étudiant à Polytech ou Administratif nous</br> vous demandons d'aller vers la page qui vous concerne</br>
						Pour ce faire clicez sur <a>Inscription</a> </strong></font>
				</P>
			</div>
			<div class="position">

				<!----------------------------------------------------la colonne du centre----------------------------------------------------------------->

				<div class="colonne_centre ">

					<?php
					// Connects to your Database

					mysql_connect("localhost", "root", "1") or die(mysql_error());

					mysql_select_db("polytech") or die(mysql_error());

					//This code runs if the form has been submitted
	
					if (isset($_POST['submit'])) {
						
						// checks if the email is in use

						if (!get_magic_quotes_gpc()) {
		
							$_POST['email'] = addslashes($_POST['email']);
		
						}
				
					
						$usercheck = $_POST['email'];

						$check = mysql_query("SELECT user_email FROM users WHERE user_email = '$usercheck'")

						or die(mysql_error());

						$check2 = mysql_num_rows($check);

						//if the name exists it gives an error

						if ($check2 != 0) {

							die('Sorry, the email '.$_POST['email'].' is already in use.');

						}
		
						//check if both passwords are equals:
						if($_POST['password'] != $_POST['pass2']){
							die('passwords do not match. Please try again.');						
						}

						if ($check2 != 0) {

							die('Sorry, the email '.$_POST['email'].' is already in use.');
						}		

						// here we encrypt the user_pass and add slashes if needed

						$_POST['password'] = sha1($_POST['password']);

						if (!get_magic_quotes_gpc()) {

							$_POST['password'] = addslashes($_POST['password']);

							$_POST['email'] = addslashes($_POST['email']);

						}

						// now we insert it into the database

						$insert = "INSERT INTO users (user_name,user_pass,user_email,user_date,user_level,user_lastname,user_tel,user_anne_dip,fonction,entreprise) VALUES (
						'".$_POST['first_name']."',
						'".$_POST['password']."',
						'".$_POST['email']."',
						NOW(),
						1,
						'".$_POST['last_name']."',
						'".$_POST['tel']."',
						'".$_POST['anne_dip']."',
						'".$_POST['fonction']."',
						'".$_POST['entreprise']."')"
						;

						$add_member = mysql_query($insert);
						if(!$add_member)
						{
							echo 'Something went wrong while registering. Please try again later.';
							echo mysql_error(); //debugging purposes, uncomment when needed
						}
						else
						?>

						<h1>Registered</h1>

						<p>
							Thank you, you have registered - you may now <a href="login.php">login</a>.
						</p>

						<?php
					}

					else
					{
						
						
					}
					?>

					<h1>Inscription</h1>

					<div id="Box_externe">

						<h2>Creation de compte</h2>

						<form id="RegisterUserForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
							<fieldset>

								<h3>Information personnelles</h3>
								<p>
									<label for="Nom">Nom*</label>
									<input id="Nom" required name="last_name" type="text" class="text" placeholder="Nom" />
								</p>

								<p>
									<label for="Prenom">Prenom*</label>
									<input id="Prenom" required name="first_name" type="text" class="text" placeholder="Prenom" />
								</p>

								<p>
									<label for="tel">Numero de telephone</label>
									<input id="tel" name="tel" type="tel" class="text" value="" />
								</p>

								<p>
									<label for="email">Email*</label>
									<input id="email" required name="email" type="email" class="text" placeholder="exemple@xyz.com" />
								</p>

								<p>

									<label for = "password"> Entrez votre mot de passe</label>
									<input type = "password" name="password" id = "password" class="text" value="" >
									<span class ="error"></span>
									<span class="bar"></span>
									<script src ="script/jquery.js" ></script>
									<script src ="script/function.js" ></script>
								</p>

								<p>

									<label for = "conf_password"> Confirmation de mot de passe*</label>
									<input type = "password" required name="pass2" id = "conf_password" class="text" value="" >
									<script src ="script/jquery.js" ></script>
									<script src ="script/function.js" ></script>								
								</p>

								<h3>Information generales</h3>

								<p>
									<label for="anne_dip">Annee de diplomation</label>
									<input id="anne_dip" name="anne_dip" type="text" class="text" value="" />
								</p>

								<p>
									<label for="Fonction">Fonction</label>
									<input id="Fonction" name="fonction" type="text" class="text" placeholder="ex: Chef de projet" />
								</p>

								<p>
									<label for="Entreprise">Entreprise </label>
									<input id="Entreprise" name="entreprise" type="text" class="text" value="" />
								</p>

								<p>
									<input id="acceptTerms" required name="acceptTerms" type="checkbox" />
									<label for="acceptTerms"> J'accepte Les <a href=""> termes d'utilisation du site IG </a> </label>
								</p>

								<p>
									<input type = "submit" name = "submit" required value = "Register">
								</p>

							</fieldset>

						</form>
					</div>

				</div>

	</body>
</html>
